package com.scott.ch05.filter;

import org.springframework.core.io.Resource;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.ClassMetadata;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.filter.TypeFilter;

import java.io.IOException;

public class ScottTypeFilter implements TypeFilter {

    /**
     *
     * @param metadataReader 读取到当前正在扫描的类的信息
     * @param metadataReaderFactory 一个可以获取其他类的信息的工厂类
     * @return
     * @throws IOException
     */
    @Override
    public boolean match(MetadataReader metadataReader,
                         MetadataReaderFactory metadataReaderFactory) throws IOException {
        //1、获取当前类的注解信息
        AnnotationMetadata annotationMetadata = metadataReader.getAnnotationMetadata();

        //2、获取当前正在扫描的类信息 [比如类型 实现的接口]
        ClassMetadata classMetadata = metadataReader.getClassMetadata();
        //3、获取当前类的资源 类路径
        Resource resource = metadataReader.getResource();

        String className = classMetadata.getClassName();
        System.out.println(">>" + className);

        if (className.contains("Teacher")) {
            return true;
        }
        return false;
    }
}
